package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsPermissionMapper;
import net.anzhuo.entity.GsPermission;
import net.anzhuo.service.GsPermissionService;
@Service
public class GsPermissionServiceImpl implements GsPermissionService {

	@Autowired
	private GsPermissionMapper gsPermissionMapper;
	
	@Override
	public GsPermission getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsPermissionMapper.getById(id);
	}

	@Override
	public List<GsPermission> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsPermissionMapper.getByCoMd5(coMd5);
	}
	
	@Override
	public List<GsPermission> getByUpdateTime(GsPermission gs) {
		// TODO Auto-generated method stub
		return gsPermissionMapper.getByUpdateTime(gs);
	}

	@Override
	public PaginationVO<GsPermission> getListWithPage(GsPermission gsPunishment) {
		PaginationVO<GsPermission> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsPermissionMapper.getListWithPage(gsPunishment));
		paginationVO.setTotalCount(gsPermissionMapper.getCount(gsPunishment.getCoMd5()));
		paginationVO.setTotalPage((gsPermissionMapper.getCount(gsPunishment.getCoMd5())-1)  / gsPunishment.getPageSize()+1);
		paginationVO.setPageNo(gsPunishment.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsPermission> getList() {
		// TODO Auto-generated method stub
		return  gsPermissionMapper.getList();
	}

	@Override
	public List<GsPermission> getList(GsPermission gsPunishment) {
		// TODO Auto-generated method stub
		return gsPermissionMapper.getListByQuery(gsPunishment);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsPermission gsPunishment) {
		// TODO Auto-generated method stub
		gsPermissionMapper.update(gsPunishment);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsPermission gsPunishment) {
		// TODO Auto-generated method stub
		gsPermissionMapper.save(gsPunishment);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsPermission gsPunishment = gsPermissionMapper.getById(id);
		if (gsPunishment == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsPermissionMapper.update(gsPunishment);

	}

}
